package com.itheima.controller;

import com.itheima.dto.MessageConstant;
import com.itheima.dto.PageResult;
import com.itheima.dto.QueryPageBean;
import com.itheima.dto.Result;
import com.itheima.pojo.CheckGroup;
import com.itheima.service.CheckGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/checkgroup")
public class CheckGroupController {
    @Autowired
    private CheckGroupService checkGroupService;
    //分页查询
    @PostMapping("/findPage")
    public PageResult queryByPage(@RequestBody QueryPageBean queryPageBean) {
        PageResult pageResult = checkGroupService.queryByPage(queryPageBean);

        return pageResult;
    }


    @PostMapping
    public Result addCheckGroup(@RequestParam List<Integer> checkitemIds, @RequestBody CheckGroup checkGroup) {
        checkGroupService.save(checkitemIds,checkGroup);
        return Result.success("新增检查组成功");
    }
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id){
        checkGroupService.deleteById(id);
        return Result.success("删除检查组成功");
    }
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        Result result=checkGroupService.getById(id);
        return result;
    }
    @GetMapping("/checkItem/{id}")
    public Result getItemIdsById(@PathVariable Integer id){
        Result result=checkGroupService.getItemIdsById(id);
        return result;
    }
    @PutMapping
    public Result updateByIds(@RequestParam List<Integer> checkitemIds, @RequestBody CheckGroup checkGroup){
        checkGroupService.updateByIds(checkitemIds,checkGroup);
        return Result.success("编辑检查组成功");
    }
    //查询所有的检查组数据
    @GetMapping("/list")
    public Result selectAllGroup() {
        Result result = checkGroupService.selectAllGroup();
        return result;
    }

}
